package main

import "fmt"

// 联想路边撸串烧烤的场景，有烤羊肉，烧鸡翅命令，有烤串师傅，和服务员MM。根据命令模式，设计烤串场景

type BarbecueMaster struct {
}

func (b *BarbecueMaster) BarbecueSheep() {
	fmt.Println("烤串师傅烤了羊肉串...")
}

func (b *BarbecueMaster) BarbecueChicken() {
	fmt.Println("烤串师傅烤了鸡翅...")
}

type Canmmand interface {
	Barbecue()
}

type CammandSheep struct {
	barbecueMaster *BarbecueMaster
}

func (cms *CammandSheep) Barbecue() {
	cms.barbecueMaster.BarbecueSheep()
}

type CammandChicken struct {
	barbecueMaster *BarbecueMaster
}

func (cmc *CammandChicken) Barbecue() {
	cmc.barbecueMaster.BarbecueChicken()
}

// 服务员

type Waiter struct {
	cmdList []Canmmand // 收集命令
}

func (w *Waiter) Notify() {
	if w.cmdList == nil {
		return
	}
	for _, cmd := range w.cmdList {
		cmd.Barbecue()
	}
}

// 业务层

func main() {
	bMaster := new(BarbecueMaster)
	cmdSheep := CammandSheep{barbecueMaster: bMaster}
	cmdChicken := CammandChicken{barbecueMaster: bMaster}

	// 服务员
	waiter := new(Waiter)

	// 收集命令
	waiter.cmdList = append(waiter.cmdList, &cmdSheep)
	waiter.cmdList = append(waiter.cmdList, &cmdChicken)

	waiter.Notify()
}
